<!--- -------------------------------------------------
NAME: 	cart_to_struct.cfm
DESC:	parses the shopping cart that now comes out of get_shpntax. 
-------------------------------------------------- --->
<cfsetting enablecfoutputonly="yes">
<cfparam name="attributes.debug" default="false">

<cfscript>
tmpcart = structnew();

var.lncount = 0;
tmpcart.this_lnitem = arraynew(1);
</cfscript>

<cfif isdefined("attributes.xml_data.child_list")>
	  <cfloop index="ln_items" list="#attributes.xml_data.child_list#">
		<cfset var.lncount = var.lncount + 1>
		<cfscript>
			tmpcart.this_lnitem[var.lncount] = structnew();		
			ln_struct = StructFind(attributes.xml_data, ln_items);		
		</cfscript>
		<cfif structkeyexists(ln_struct,"product")>
			<cfscript>
				if(isdefined("ln_struct.product.status.inner_text")) {
					tmpcart.this_lnitem[var.lncount].stock_status = ln_struct.product.status.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].stock_status = "";
				}
		
				if(isdefined("ln_struct.product.product_code.inner_text")) {
					tmpcart.this_lnitem[var.lncount].product_code = ln_struct.product.product_code.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].product_code = "";
				}	
		
				if(isdefined("ln_struct.product.product_desc.inner_text")) {
					tmpcart.this_lnitem[var.lncount].product_desc = ln_struct.product.product_desc.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].product_desc = "";
				}
		
				if(isdefined("ln_struct.product.quantity.inner_text")) {
					tmpcart.this_lnitem[var.lncount].quantity = ln_struct.product.quantity.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].quantity = "";
				}
				
				if(isdefined("ln_struct.product.recycle_fee.inner_text")) {
					tmpcart.this_lnitem[var.lncount].recycle_fee = ln_struct.product.recycle_fee.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].recycle_fee = "";
				}

				if(isdefined("ln_struct.product.esd.inner_text")) {
					tmpcart.this_lnitem[var.lncount].esd = ln_struct.product.esd.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].esd = "";
				}
				
				if(isdefined("ln_struct.product.price.inner_text")) {
					tmpcart.this_lnitem[var.lncount].price = ln_struct.product.price.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].price = "";
				}	
				
				if(isdefined("ln_struct.product.list_price.inner_text")) {
					tmpcart.this_lnitem[var.lncount].list_price = ln_struct.product.list_price.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].list_price = "";
				}	
				
				if(isdefined("ln_struct.product.floor_price.inner_text")) {
					tmpcart.this_lnitem[var.lncount].floor_price = ln_struct.product.floor_price.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].floor_price = "";
				}	
		
				if(isdefined("ln_struct.product.ln.inner_text")) {
					tmpcart.this_lnitem[var.lncount].ln = ln_struct.product.ln.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].ln = "";
				}
		
				if(isdefined("ln_struct.product.status.inner_text")) {
					tmpcart.this_lnitem[var.lncount].status = ln_struct.product.status.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].status = "";
				}
				
				if(isdefined("ln_struct.product.rsn_code_prc.inner_text")) {
					tmpcart.this_lnitem[var.lncount].rsn_code_prc = ln_struct.product.rsn_code_prc.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].rsn_code_prc = "";
				}
				
				if(isdefined("ln_struct.product.bid.inner_text")) {
					tmpcart.bid = ln_struct.product.bid.inner_text;
				}
				
				if(isdefined("ln_struct.product.esd.inner_text")) {
					tmpcart.this_lnitem[var.lncount].esd = ln_struct.product.esd.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].esd = "";
				}

	//start: 3005 :: construct for warranty info
				var.wtycount = 0;
				wtyloop = 0;

				if(isdefined("ln_struct.product.warranty")) {
					tmpcart.this_lnitem[var.lncount].warranty = arraynew(1);
				}
			</cfscript>
<!--- 			<cfloop index="wty_items" list="#ln_struct.product.child_list#">	
				<cfif findnocase("warranty",wty_items)>
					<cfset wtyloop = wtyloop + 1>
					<cfscript>
						wty_struct = StructFind(ln_struct.product, wty_items);
						tmpcart.this_lnitem[var.lncount].warranty[wtyloop] = 	structnew();
						if(isdefined("ln_struct.product.warranty.model_number.inner_text")) {
							tmpcart.this_lnitem[var.lncount].warranty[wtyloop].model = wty_struct.model_number.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].warranty[wtyloop].model = "";
						}
						if(isdefined("ln_struct.product.warranty.serial.inner_text")) {
							tmpcart.this_lnitem[var.lncount].warranty[wtyloop].serial = wty_struct.serial.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].warranty[wtyloop].serial = "";
						}
						if(isdefined("ln_struct.product.warranty.purchase_date.inner_text")) {
							tmpcart.this_lnitem[var.lncount].warranty[wtyloop].date = wty_struct.purchase_date.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].warranty[wtyloop].date = "";
						}
					</cfscript>
				</cfif>
			</cfloop> --->
<!--- 	//end: 3005 :: construct for warranty info --->
			<!--- <cfif attributes.simple_serial>
				<cfscript>
					if(isdefined("ln_struct.product.serial_number.inner_text")) {
						tmpcart.this_lnitem[var.lncount].serial_number = ln_struct.product.serial_number.inner_text;
					} else {
						tmpcart.this_lnitem[var.lncount].serial_number = "";
					}
				</cfscript>
			<cfelse>
				<cfscript>
					var.serial_count = 0;
					var.serial_list = "";
					tmpcart.this_lnitem[var.lncount].serial_number = arraynew(1);
				</cfscript>		
				<cfif isdefined("ln_struct.product.serial_number.inner_text")>
					<cfscript>
						var.tmplist = ln_struct.product.child_list;
					
						while(listlen(var.tmplist)) {
							if(listfirst(left(var.tmplist,"13")) eq "serial_number") {
								var.serial_list = listappend(var.serial_list, listfirst(var.tmplist));
							}
							var.tmplist = listrest(var.tmplist);
						}
					</cfscript>
					<cfloop index="ln_serials" list="#var.serial_list#">
						<cfscript>
							var.serial_count = var.serial_count + 1;
							tmpcart.this_lnitem[var.lncount].serial_number[var.serial_count] = structnew();
			
							ln_serial = StructFind(ln_struct.product, ln_serials);

							if(isdefined("ln_serial.inner_text")) {
								tmpcart.this_lnitem[var.lncount].serial_number[var.serial_count] = ln_serial.inner_text;
							} else {
								tmpcart.this_lnitem[var.lncount].serial_number[var.serial_count] = "";
							}
							if (var.serial_count gt 5000) { break; }
						</cfscript>
					</cfloop>
				</cfif>
			</cfif> --->
		</cfif>
		<cfif structkeyexists(ln_struct,"configuration")>
			<cfscript>
				tmpcart.this_lnitem[var.lncount].configuration = structnew();
				
				if(isdefined("ln_struct.configuration.baseunit.ln.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.base_ln = ln_struct.configuration.baseunit.ln.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.base_ln = "";
				}

				if(isdefined("ln_struct.configuration.baseunit.price.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.base_price = ln_struct.configuration.baseunit.price.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.base_price = "";
				}	
				
				if(isdefined("ln_struct.configuration.list_price.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.list_price = ln_struct.configuration.list_price.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.list_price = "";
				}	
				
				if(isdefined("ln_struct.configuration.floor_price.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.floor_price = ln_struct.configuration.floor_price.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.floor_price = "";
				}	
		
				if(isdefined("ln_struct.configuration.baseunit.product_code.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.base_product_code = ln_struct.configuration.baseunit.product_code.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.base_product_code = "";
				}		

				if(isdefined("ln_struct.configuration.baseunit.rsn_code_prc.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.rsn_code_prc = ln_struct.configuration.baseunit.rsn_code_prc.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.rsn_code_prc = "";
				}	

	//start: 3005 :: construct for warranty info
				var.wtycount = 0;
				wtyloop = 0;

				if(isdefined("ln_struct.configuration.warranty")) {
					tmpcart.this_lnitem[var.lncount].configuration.warranty = arraynew(1);
				}
			</cfscript>
			<cfloop index="wty_items" list="#ln_struct.configuration.child_list#">	
				<cfif findnocase("warranty",wty_items)>
					<cfset wtyloop = wtyloop + 1>
					<cfscript>
						wty_struct = StructFind(ln_struct.configuration, wty_items);		
						tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop] = 	structnew();
						if(isdefined("ln_struct.configuration.warranty.model_number.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop].model = wty_struct.model_number.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop].model = "";
						}
						if(isdefined("ln_struct.configuration.warranty.serial.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop].serial = wty_struct.serial.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop].serial = "";
						}
						if(isdefined("ln_struct.configuration.warranty.purchase_date.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop].date = wty_struct.purchase_date.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.warranty[wtyloop].date = "";
						}				
					</cfscript>
				</cfif>
			</cfloop>
<!--- 	//end: 3005 :: construct for warranty info --->
				
			<cfscript>
				if(isdefined("ln_struct.configuration.baseunit.product_desc.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.base_product_desc = ln_struct.configuration.baseunit.product_desc.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.base_product_desc = "";
				}

				if(isdefined("ln_struct.configuration.baseunit.status.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.base_status = ln_struct.configuration.baseunit.status.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.base_status = "";
				}

				if(isdefined("ln_struct.configuration.quantity.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.quanity = ln_struct.configuration.quantity.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.quanity = "";
				}
				
				
				if(isdefined("ln_struct.configuration.esd.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.esd = ln_struct.configuration.esd.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.esd = "";
				}

				if(isdefined("ln_struct.configuration.baseunit.rsn_code_prc.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.rsn_code_prc = ln_struct.configuration.baseunit.rsn_code_prc.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.rsn_code_prc = "";
				}
				
				if(isdefined("ln_struct.configuration.baseunit.bid.inner_text")) {
					tmpcart.bid = ln_struct.configuration.baseunit.bid.inner_text;
				}

				if(isdefined("ln_struct.configuration.baseunit.esd.inner_text")) {
					tmpcart.this_lnitem[var.lncount].configuration.esd = ln_struct.configuration.baseunit.esd.inner_text;
				} else {
					tmpcart.this_lnitem[var.lncount].configuration.esd = "";
				}
			</cfscript>
			<!--- <cfif attributes.simple_serial>
				<cfscript>
					if(isdefined("ln_struct.configuration.baseunit.serial_number.inner_text")) {
						tmpcart.this_lnitem[var.lncount].configuration.serial_number = ln_struct.configuration.baseunit.serial_number.inner_text;
					} else {
						tmpcart.this_lnitem[var.lncount].configuration.serial_number = "";
					}
				</cfscript>
			<cfelse>
				<cfscript>
					var.serial_count = 0;
					var.serial_list = "";
					tmpcart.this_lnitem[var.lncount].configuration.serial_number = arraynew(1);
				</cfscript>		
				<cfif isdefined("ln_struct.configuration.baseunit.serial_number.inner_text")>
					<cfscript>
						var.tmplist = ln_struct.configuration.baseunit.child_list;
					
						while(listlen(var.tmplist)) {
							if(listfirst(left(var.tmplist,"13")) eq "serial_number") {
								var.serial_list = listappend(var.serial_list, listfirst(var.tmplist));
							}
							var.tmplist = listrest(var.tmplist);
						}
					</cfscript>
					<cfloop index="ln_serials" list="#var.serial_list#">
						<cfscript>
							var.serial_count = var.serial_count + 1;
							tmpcart.this_lnitem[var.lncount].configuration.serial_number[var.serial_count] = structnew();
			
							ln_serial = StructFind(ln_struct.configuration.baseunit, ln_serials);
			
							if(isdefined("ln_serial.inner_text")) {
								tmpcart.this_lnitem[var.lncount].configuration.serial_number[var.serial_count] = ln_serial.inner_text;
							} else {
								tmpcart.this_lnitem[var.lncount].configuration.serial_number[var.serial_count] = "";
							}
							if (var.serial_count gt 5000) { break; }
						</cfscript>
					</cfloop>
				</cfif>
			</cfif> --->
			<cfscript>
				var.component_count = 0;
				var.component_list = "";
				tmpcart.this_lnitem[var.lncount].configuration.component = arraynew(1);
			</cfscript>
			<cfif isdefined("ln_struct.configuration.component.child_list")>
				<cfscript>
					var.tmplist = ln_struct.configuration.child_list;
				
					while(listlen(var.tmplist)) {
						if(listfirst(left(var.tmplist,"9")) eq "component") {
							var.component_list = listappend(var.component_list, listfirst(var.tmplist));
						}
						var.tmplist = listrest(var.tmplist);
					}
				</cfscript>
				<cfloop index="ln_components" list="#var.component_list#">
					<cfscript>
						var.component_count = var.component_count + 1;
						tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count] = structnew();
		
						ln_component = StructFind(ln_struct.configuration, ln_components);

						if(isdefined("ln_component.ln.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].ln = ln_component.ln.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].ln = "";
						}	

						if(isdefined("ln_component.price.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].price = ln_component.price.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].price = "";
						}

						if(isdefined("ln_component.product_code.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].product_code = ln_component.product_code.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].product_code = "";
						}

						if(isdefined("ln_component.product_desc.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].product_desc = ln_component.product_desc.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].product_desc = "";
						}

						if(isdefined("ln_component.quantity.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].quantity = ln_component.quantity.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].quantity = "";
						}
						
						if(isdefined("ln_component.recycle_fee.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].recycle_fee = ln_component.recycle_fee.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].recycle_fee = "";
						}

						if(isdefined("ln_component.rsn_code_prc.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].rsn_code_prc = ln_component.rsn_code_prc.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].rsn_code_prc = "";
						}

						if(isdefined("ln_component.esd.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].esd = ln_component.esd.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].esd = "";
						}

						if(isdefined("ln_component.opt_type.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].opt_type = ln_component.opt_type.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].opt_type = "";
						}

						if(isdefined("ln_component.status.inner_text")) {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].status = ln_component.status.inner_text;
						} else {
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].status = "";
						}

						if (var.component_count gt 5000) { break; }
					</cfscript>
					<!--- <cfif attributes.simple_serial>
						<cfscript>
							if(isdefined("ln_struct.configuration.baseunit.serial_number.inner_text")) {
								tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].serial_number = ln_struct.configuration.baseunit.serial_number.inner_text;
							} else {
								tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].serial_number = "";
							}
						</cfscript>
					<cfelse>
						<cfscript>
							var.ln_component_serial_list = "";
							var.ln_component_serial_count = 0;
							tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].serial_number = arraynew(1);
						</cfscript>					
						<cfif isdefined("ln_component.serial_number.inner_text")>
							<cfscript>
								var.tmplist = ln_component.child_list;
							
								while(listlen(var.tmplist)) {
									if(listfirst(left(var.tmplist,"13")) eq "serial_number") {
										var.ln_component_serial_list = listappend(var.ln_component_serial_list, listfirst(var.tmplist));
									}
									var.tmplist = listrest(var.tmplist);
								}
							</cfscript>
							<cfloop index="ln_component_ln_serials" list="#var.ln_component_serial_list#">
								<cfscript>
									var.ln_component_serial_count = var.ln_component_serial_count + 1;
									tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].serial_number[var.ln_component_serial_count] = structnew();
					
									ln_component_ln_serial = StructFind(ln_struct, ln_component_ln_serials);
					
									if(isdefined("ln_component_ln_serial.inner_text")) {
										tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].serial_number[var.ln_component_serial_count] = ln_component_ln_serial.inner_text;
									} else {
										tmpcart.this_lnitem[var.lncount].configuration.component[var.component_count].serial_number[var.ln_component_serial_count] = "";
									}
									if (var.ln_component_serial_count gt 5000) { break; }
								</cfscript>
							</cfloop>
						</cfif>
					 </cfif>--->
				</cfloop>
			</cfif>
		</cfif>
		
	<cfset temp = setvariable('caller.' & attributes.returnvar, tmpcart)>

	</cfloop>

<cfelse>
	<cfthrow message="No Shopping Cart" type="xti" detail="XTI did not return a shopping cart!" errorcode="911">
</cfif>

<cfsetting enablecfoutputonly="no">